/**
 * Copyright (c) 2004-2006, Martin Fiedler
 * All rights reserved.
 * 
 * Redistribution and use in source and binary forms, with or without modification, 
 * are permitted provided that the following conditions are met:
 * 
 * 1. Redistributions of source code must retain the above copyright notice, 
 *    this list of conditions and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright notice, 
 *    this list of conditions and the following disclaimer in the documentation 
 *    and/or other materials provided with the distribution.
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 
 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 
 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR 
 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 
 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 
 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 
 * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, 
 * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 **/
 
#include "common.h"
#include "input.h"
#include "nal.h"
#include "cavlc.h"
#include "params.h"
#include "slicehdr.h"


int main(int argc, char *argv[]) {
  nal_unit unit;
  seq_parameter_set sps;
  pic_parameter_set pps;
  slice_header sh;
  int count;

  if(!input_open("../../../../../input/h264/manitu.264")) return 1;

  for(count=1; get_next_nal_unit(&unit); ++count)
    switch(unit.nal_unit_type) {
      case 7: decode_seq_parameter_set(&sps); break;
      case 8: decode_pic_parameter_set(&pps); break;
      case 1: case 5:
        decode_slice_header(&sh,&sps,&pps,&unit);
        printf("%s at unit #%d (frame_num=%d)\n",
               _str_slice_type(sh.slice_type),count,sh.frame_num);
        printf("  RefID=0x%08X first_mb_in_slice=%d field_pic=%d\n",
               sh.pic_parameter_set_id,sh.first_mb_in_slice,sh.field_pic_flag);
        printf("  MbaffFrameFlag=%d PicSizeInSamples=%dx%d\n",
               sh.MbaffFrameFlag,sps.PicWidthInSamples,sh.PicHeightInSamples);
        printf("  idr_pic_id=0x%04X pic_order_cnt_lsb=%d redundant_pic_cnt=%d\n",
               sh.idr_pic_id,sh.pic_order_cnt_lsb,sh.redundant_pic_cnt);
        printf("  direct_spatial_mv_pred=%d num_ref_idx_active_override=%d\n",
               sh.direct_spatial_mv_pred_flag,sh.num_ref_idx_active_override_flag);
        printf("  ref_pic_list_reordering=%d/%d adaptive_ref_pic_marking=%d\n",
               sh.ref_pic_list_reordering_flag_l0,sh.ref_pic_list_reordering_flag_l1,
               sh.adaptive_ref_pic_marking_mode_flag);
        printf("  slice_qp_delta=%d slice_qs_delta=%d\n",
               sh.slice_qp_delta,sh.slice_qs_delta);
        break;
    }

  input_close();
  return 0;
}
